package com.TeacherInfoServer.mapper;

import com.TeacherInfoServer.pojo.DTO.SearchDTO.PostDoctoralSearchDTO;
import com.TeacherInfoServer.pojo.entity.PostDoctoral;
import com.TeacherInfoServer.pojo.vo.PostDoctoralVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PostDoctoralMapper extends BaseMapper<PostDoctoral> {
    List<PostDoctoral> selectPageWithTeacher(Page<PostDoctoral> page);

    @Select("<script>" +
            "SELECT p.*, t.teacher_name " +
            "FROM postdoctoral_management p " +
            "LEFT JOIN teacher t ON p.teacher_id = t.teacher_id " +
            "<where> " +
            "<if test='search.teacherId != null and search.teacherId.trim() != \"\"'> " +
            "AND p.teacher_id LIKE CONCAT('%', #{search.teacherId}, '%') " +
            "</if> " +
            "<if test='search.teacherName != null and search.teacherName.trim() != \"\"'> " +
            "AND t.teacher_name LIKE CONCAT('%', #{search.teacherName}, '%') " +
            "</if> " +
            "<if test='search.researchUnit != null and search.researchUnit.trim() != \"\"'> " +
            "AND p.research_unit LIKE CONCAT('%', #{search.researchUnit}, '%') " +
            "</if> " +
            "<if test='search.entryDate != null and search.entryDate.trim() != \"\" and search.exitDate != null and search.exitDate.trim() != \"\"'> " +
            "AND p.entry_date  &lt;= #{search.exitDate} " +
            "AND (p.exit_date &gt;= #{search.entryDate} OR p.exit_date IS NULL) " +
            "</if> " +
            "</where> " +
            "</script>")
    Page<PostDoctoralVo> searchPostDoctoralList(Page<?> page, @Param("search") PostDoctoralSearchDTO search);
}
